package com.example.NotePad;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import android.util.Base64;

public class GetNoteListFunc {
	private List<ListDetails> detailsList = null;
	private static final String LISTPATH ="/sdcard/1.txt"; 
	public static String[] ss = new String[100];
	ListDetails aListDetails = new ListDetails();
	//add by lt 2011-04-09
	private static final String FILEPATH ="/sdcard/note/note.properties"; 
	
	
	public List<ListDetails> getNoteList(){ 
		
		
		  detailsList =  new ArrayList<ListDetails>(); 
		  try { 
			  
			   //delete by lt 2011-04-09
//			   FileReader read = new FileReader(LISTPATH); 
			   //add by lt 2011-04-09
			   FileReader read = new FileReader(FILEPATH); 
			   BufferedReader br = new BufferedReader(read); 
			   String row; 
			   while((row = br.readLine())!=null){ 
			    System.out.println(row); 
			    //add by lt 2011-04-09
			    if (row.startsWith("#")) {
			    	continue;
			    }
			    row = row.substring(row.indexOf("=") + 1, row.length());
			    ss = row.split(",");
//			    for (int i = 0; i < ss.length; i++) 
//			    	System.out.println(ss[i]);			    	


			    
			    ListDetails aListDetails = new ListDetails();
			    aListDetails.setNoteId(ss[0]);			     
			    aListDetails.setNoteName(ss.length>1?ss[1]:null);
			    aListDetails.setNoteContent(ss.length>2?ss[2]:null);
			    //add by lt 2011-04-09
			    aListDetails.setNoteId(ss[0]);			     
				aListDetails.setNoteName(ss.length > 1 ? new String(Base64
				        .decode(ss[1].substring(ss[1].indexOf("\n") + 1, ss[1]
				                .length()), Base64.DEFAULT)) : "");
				aListDetails.setNoteContent(ss.length > 2 ? new String(Base64
				        .decode(ss[2].substring(ss[2].indexOf("\n") + 1, ss[2]
				                .length()), Base64.DEFAULT)) : "");
			    detailsList.add(aListDetails);
			    System.out.println(ss.length);
			   
		   }
		  } catch (FileNotFoundException e) { 
		   e.printStackTrace(); 
		  } catch (IOException e){ 
		   e.printStackTrace(); 
		  }
		return detailsList;
		  
		}
	
	public void decodeContent(){
		
	}
	
}
